<!-- build time:Tue Jul 21 2020 12:41:22 GMT+0800 (GMT+08:00) --><!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=2"><meta name="theme-color" content="#222"><meta name="generator" content="Hexo 4.2.0"><link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png"><link rel="icon" type="image/png" sizes="32x32" href="/img/blog_favicon/favicon-32x32-next.png"><link rel="icon" type="image/png" sizes="16x16" href="/img/blog_favicon/favicon-16x16-next.png"><link rel="mask-icon" href="/images/logo.svg" color="#222"><meta name="baidu-site-verification" content="r15J5zOS2KI43yBS"><link rel="stylesheet" href="/css/main.css"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"><link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/pace/1.0.2/themes/blue/pace-theme-minimal.min.css"><script src="//cdnjs.cloudflare.com/ajax/libs/pace/1.0.2/pace.min.js"></script><script id="hexo-configurations">var NexT=window.NexT||{},CONFIG={hostname:new URL("http://www.zhengjiaao.cn").hostname,root:"/",scheme:"Muse",version:"7.6.0",exturl:!1,sidebar:{position:"left",display:"post",padding:18,offset:12,onmobile:!1},copycode:{enable:!0,show_result:!0,style:null},back2top:{enable:!0,sidebar:!1,scrollpercent:!0},bookmark:{enable:!0,color:"#222",save:"auto"},fancybox:!0,mediumzoom:!1,lazyload:!1,pangu:!1,comments:{style:"tabs",active:"valine",storage:!0,lazyload:!1,nav:null,activeClass:"valine"},algolia:{appID:"",apiKey:"",indexName:"",hits:{per_page:10},labels:{input_placeholder:"Search for Posts",hits_empty:"We didn't find any results for the search: ${query}",hits_stats:"${hits} results found in ${time} ms"}},localsearch:{enable:!0,trigger:"auto",top_n_per_article:1,unescape:!1,preload:!1},path:"search.xml",motion:{enable:!0,async:!1,transition:{post_block:"fadeIn",post_header:"slideDownIn",post_body:"slideDownIn",coll_header:"slideLeftIn",sidebar:"slideUpIn"}}}</script><meta property="og:type" content="article"><meta property="og:title" content="github-fork后两个仓库之间如何同步代码"><meta property="og:url" content="http://www.zhengjiaao.cn/posts/2149577032.html"><meta property="og:site_name" content="宇宙小神特别萌"><meta property="og:locale" content="zh_CN"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-47c323be9985b701.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-8924629b1b4caca2.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-2b9859fa568b7ece.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-8ba6a8c2767864f5.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-76f280ef91be6375.png"><meta property="article:published_time" content="2020-01-03T08:14:51.000Z"><meta property="article:modified_time" content="2020-07-20T10:37:55.324Z"><meta property="article:author" content="宇宙小神特别萌"><meta property="article:tag" content="Git"><meta name="twitter:card" content="summary"><meta name="twitter:image" content="https://upload-images.jianshu.io/upload_images/15645795-47c323be9985b701.png"><link rel="canonical" href="http://www.zhengjiaao.cn/posts/2149577032.html"><script id="page-configurations">CONFIG.page={sidebar:"",isHome:!1,isPost:!0}</script><title>github-fork后两个仓库之间如何同步代码 | 宇宙小神特别萌</title><noscript><style>.sidebar-inner,.use-motion .brand,.use-motion .collection-header,.use-motion .comments,.use-motion .menu-item,.use-motion .pagination,.use-motion .post-block,.use-motion .post-body,.use-motion .post-header{opacity:initial}.use-motion .site-subtitle,.use-motion .site-title{opacity:initial;top:initial}.use-motion .logo-line-before i{left:initial}.use-motion .logo-line-after i{right:initial}</style></noscript><link rel="alternate" href="/atom.xml" title="宇宙小神特别萌" type="application/atom+xml"></head><body itemscope itemtype="http://schema.org/WebPage"><div class="container use-motion"><div class="headband"></div><header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="header-inner"><div class="site-brand-container"><div class="site-meta custom-logo"><div class="site-meta-headline"><a><img class="custom-logo-image" src="/img/blog_favicon/favicon-32x32-next.png" alt="宇宙小神特别萌"></a></div><div><a href="/" class="brand" rel="start"><span class="logo-line-before"><i></i></span> <span class="site-title">宇宙小神特别萌</span> <span class="logo-line-after"><i></i></span></a></div><p class="site-subtitle">ZhengJa</p></div><div class="site-nav-toggle"><div class="toggle" aria-label="切换导航栏"><span class="toggle-line toggle-line-first"></span> <span class="toggle-line toggle-line-middle"></span> <span class="toggle-line toggle-line-last"></span></div></div></div><nav class="site-nav"><ul id="menu" class="menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签<span class="badge">27</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档<span class="badge">116</span></a></li><li class="menu-item menu-item-sitemap"><a href="/sitemap.xml" rel="section"><i class="fa fa-fw fa-sitemap"></i>站点地图</a></li><li class="menu-item menu-item-messageboard"><a href="/messageboard/" rel="section"><i class="fa fa-fw fa-address-book"></i>留言板</a></li><li class="menu-item menu-item-links"><a href="/links/" rel="section"><i class="fa fa-fw fa-user-plus"></i>友链</a></li><li class="menu-item menu-item-shuoshuo"><a href="/shuoshuo/" rel="section"><i class="fa fa-fw fa-file-text-o"></i>说说</a></li><li class="menu-item menu-item-search"><a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索</a></li></ul></nav><div class="site-search"><div class="popup search-popup"><div class="search-header"><span class="search-icon"><i class="fa fa-search"></i></span><div class="search-input-container"><input autocomplete="off" autocorrect="off" autocapitalize="none" placeholder="搜索..." spellcheck="false" type="text" id="search-input"></div><span class="popup-btn-close"><i class="fa fa-times-circle"></i></span></div><div id="search-result"></div></div><div class="search-pop-overlay"></div></div></div></header><div class="back-to-top"><i class="fa fa-arrow-up"></i> <span>0%</span></div><div class="reading-progress-bar"></div><a role="button" class="book-mark-link book-mark-link-fixed"></a> <a href="https://github.com/zhengjiaao" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin:130px 106px" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><main class="main"><div class="main-inner"><div class="content-wrap"><div class="content"><div class="posts-expand"><article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN"><link itemprop="mainEntityOfPage" href="http://www.zhengjiaao.cn/posts/2149577032.html"><span hidden itemprop="author" itemscope itemtype="http://schema.org/Person"><meta itemprop="image" content="/my-images/avatar.gif"><meta itemprop="name" content="宇宙小神特别萌"><meta itemprop="description" content="人生就是一次幸运的旅行！"></span><span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization"><meta itemprop="name" content="宇宙小神特别萌"></span><header class="post-header"><h1 class="post-title" itemprop="name headline">github-fork后两个仓库之间如何同步代码</h1><div class="post-meta"><span class="post-meta-item"><span class="post-meta-item-icon"><i class="fa fa-calendar-o"></i> </span><span class="post-meta-item-text">发表于</span> <time title="创建时间：2020-01-03 16:14:51" itemprop="dateCreated datePublished" datetime="2020-01-03T16:14:51+08:00">2020-01-03</time> </span><span class="post-meta-item"><span class="post-meta-item-icon"><i class="fa fa-calendar-check-o"></i> </span><span class="post-meta-item-text">更新于</span> <time title="修改时间：2020-07-20 18:37:55" itemprop="dateModified" datetime="2020-07-20T18:37:55+08:00">2020-07-20</time> </span><span id="/posts/2149577032.html" class="post-meta-item leancloud_visitors" data-flag-title="github-fork后两个仓库之间如何同步代码" title="热度"><span class="post-meta-item-icon"><i class="fa fa-eye"></i> </span><span class="post-meta-item-text">热度：</span> <span class="leancloud-visitors-count"></span> <span>℃</span> </span><span class="post-meta-item" title="热度" id="busuanzi_container_page_pv" style="display:none"><span class="post-meta-item-icon"><i class="fa fa-eye"></i> </span><span class="post-meta-item-text">热度：</span> <span id="busuanzi_value_page_pv"></span> </span><span class="post-meta-item"><span class="post-meta-item-icon"><i class="fa fa-comment-o"></i> </span><span class="post-meta-item-text">Valine：</span> <a title="valine" href="/posts/2149577032.html#comments" itemprop="discussionUrl"><span class="post-comments-count valine-comment-count" data-xid="/posts/2149577032.html" itemprop="commentCount"></span></a></span><br><span class="post-meta-item" title="本文字数"><span class="post-meta-item-icon"><i class="fa fa-file-word-o"></i> </span><span class="post-meta-item-text">本文字数：</span> <span>21k</span> </span><span class="post-meta-item" title="阅读时长"><span class="post-meta-item-icon"><i class="fa fa-clock-o"></i> </span><span class="post-meta-item-text">阅读时长 &asymp;</span> <span>19 分钟</span></span></div></header><div class="post-body" itemprop="articleBody"><meta name="referrer" content="no-referrer"><a id="more"></a><p><img src="https://upload-images.jianshu.io/upload_images/15645795-47c323be9985b701.png" alt="git合并目录.png"></p><p>说明：</p><blockquote><p>整理一份github的fork的用法 ，以及相关的操作命令 ，重点是在于fork完成了之后 ，两个仓库之间如何同步代码 ，如何保持代码相同</p><p>比如仓库A和仓库B ，B是从A上面fork出来的 ，然后分别在A,B进行了开发:<br>1.这个时候想把A,B之间的修改相互同步<br>2.如果A修改了10个 ，只想同步5个到B ，怎么操作<br>3.B修改了10个 ，想同步3个到A ，怎么操作</p></blockquote><p>需求：团队里推了使用github这种网站来协同开发 ，但是出现了个问题：fork后的代码无法 与源分支代码同步 ，导致fork分支的代码只有自己写的那部分 ，而不是各个分支merge之后的版本</p><p>源项目（ORIGINAL_REPOSITORY）：<a href="https://github.com/zhengjiaao/ORIGINAL_REPOSITORY.git" target="_blank" rel="noopener">https://github.com/zhengjiaao/ORIGINAL_REPOSITORY.git</a></p><p>Fork后的项目（YOUR_FORK）：<a href="https://github.com/zhengjiaao/YOUR_FORK.git" target="_blank" rel="noopener">https://github.com/zhengjiaao/YOUR_FORK.git</a></p><h2 id="一、两个仓库之间如何同步代码-，如何保持代码相同"><a href="#一、两个仓库之间如何同步代码-，如何保持代码相同" class="headerlink" title="一、两个仓库之间如何同步代码 ，如何保持代码相同"></a>一、两个仓库之间如何同步代码 ，如何保持代码相同</h2><h3 id="方式一：在源A仓库或Fork的B仓库上执行同步"><a href="#方式一：在源A仓库或Fork的B仓库上执行同步" class="headerlink" title="方式一：在源A仓库或Fork的B仓库上执行同步"></a>方式一：在源A仓库或Fork的B仓库上执行同步</h3><h4 id="1、将源项目代码同步到Fork出来的个人项目上："><a href="#1、将源项目代码同步到Fork出来的个人项目上：" class="headerlink" title="1、将源项目代码同步到Fork出来的个人项目上："></a>1、将源项目代码同步到Fork出来的个人项目上：</h4><p>代码：</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#拉取Fork出来的分支</span></span><br><span class="line">git clone Fork的分支url</span><br><span class="line"></span><br><span class="line"><span class="comment">#注意：进入项目根目录 ，执行下面操作</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#查看所有远程库(remote repo)的远程url</span></span><br><span class="line">git remote -v</span><br><span class="line"></span><br><span class="line"><span class="comment">#添加源分支url</span></span><br><span class="line">git remote add upstream 替换成源项目url</span><br><span class="line"></span><br><span class="line"><span class="comment">#查看所有远程库(remote repo)的远程url</span></span><br><span class="line">git remote -v</span><br><span class="line"></span><br><span class="line"><span class="comment">#从源分支获取最新的代码</span></span><br><span class="line">git fetch upstream</span><br><span class="line"></span><br><span class="line"><span class="comment">#切换到主分支</span></span><br><span class="line">git checkout master</span><br><span class="line"></span><br><span class="line"><span class="comment">#合并本地分支和源分支,本地库和远程的github原仓库同步</span></span><br><span class="line">git merge upstream/master</span><br><span class="line"></span><br><span class="line"><span class="comment">#push到fork分支,本地的仓库提交到github</span></span><br><span class="line">git push origin master</span><br></pre></td></tr></table></figure><p>演示：</p><blockquote><p>源项目的仓库(ORIGINAL_REPOSITORY)添加fork文件 ，将fork文件同步到fork后的项目仓库(YOUR_FORK)上</p></blockquote><p>下拉 fork后的仓库 ‘YOUR_FORK’ 代码</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br></pre></td><td class="code"><pre><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git remote -v</span><br><span class="line">origin  https://github.com/zhengjiaao/YOUR_FORK.git (fetch)</span><br><span class="line">origin  https://github.com/zhengjiaao/YOUR_FORK.git (push)</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git remote add upstream https://github.com/zhengjiaao/ORIGINAL_REPOSITORY.git</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git remote -v</span><br><span class="line">origin  https://github.com/zhengjiaao/YOUR_FORK.git (fetch)</span><br><span class="line">origin  https://github.com/zhengjiaao/YOUR_FORK.git (push)</span><br><span class="line">upstream        https://github.com/zhengjiaao/ORIGINAL_REPOSITORY.git (fetch)</span><br><span class="line">upstream        https://github.com/zhengjiaao/ORIGINAL_REPOSITORY.git (push)</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git fetch upstream</span><br><span class="line">From https://github.com/zhengjiaao/ORIGINAL_REPOSITORY</span><br><span class="line"> * [new branch]      master     -&gt; upstream/master</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git checkout master</span><br><span class="line">Already on 'master'</span><br><span class="line">Your branch is up to <span class="built_in">date</span> with 'origin/master'.</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git merge upstream/master</span><br><span class="line">Already up to <span class="built_in">date</span>.</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git push origin master</span><br><span class="line">Everything up-to-<span class="built_in">date</span></span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git push</span><br><span class="line">Everything up-to-<span class="built_in">date</span></span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git fetch upstream</span><br><span class="line"><span class="function">remote: <span class="title">Enumerating</span> <span class="title">objects</span>: 4, <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">remote</span>: <span class="title">Counting</span> <span class="title">objects</span>: 100% (4/4), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">remote</span>: <span class="title">Compressing</span> <span class="title">objects</span>: 100% (1/1), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">remote</span>: <span class="title">Total</span> 3 (<span class="title">delta</span> 1), <span class="title">reused</span> 3 (<span class="title">delta</span> 1), <span class="title">pack</span>-<span class="title">reused</span> 0</span></span><br><span class="line"><span class="function"><span class="title">Unpacking</span> <span class="title">objects</span>: 100% (3/3), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">From</span> <span class="title">https</span>://<span class="title">github.com</span>/<span class="title">zhengjiaao</span>/<span class="title">ORIGINAL_REPOSITORY</span></span></span><br><span class="line"><span class="function">   <span class="title">eb3614a</span>..92539<span class="title">d4</span>  <span class="title">master</span>     -&gt; <span class="title">upstream</span>/<span class="title">master</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function"><span class="title">Administrator</span>@<span class="title">ZhengJiaAo</span> <span class="title">MINGW64</span> /<span class="title">j</span>/<span class="title">IdeaTestProject</span>/<span class="title">GitHub</span>/<span class="title">YOUR_FORK</span> (<span class="title">master</span>)</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">checkout</span> <span class="title">master</span></span></span><br><span class="line"><span class="function"><span class="title">Already</span> <span class="title">on</span> '<span class="title">master</span>'</span></span><br><span class="line"><span class="function"><span class="title">Your</span> <span class="title">branch</span> <span class="title">is</span> <span class="title">up</span> <span class="title">to</span> <span class="title">date</span> <span class="title">with</span> '<span class="title">origin</span>/<span class="title">master</span>'.</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function"><span class="title">Administrator</span>@<span class="title">ZhengJiaAo</span> <span class="title">MINGW64</span> /<span class="title">j</span>/<span class="title">IdeaTestProject</span>/<span class="title">GitHub</span>/<span class="title">YOUR_FORK</span> (<span class="title">master</span>)</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">merge</span> <span class="title">upstream</span>/<span class="title">master</span></span></span><br><span class="line"><span class="function"><span class="title">Updating</span> <span class="title">eb3614a</span>..92539<span class="title">d4</span></span></span><br><span class="line"><span class="function"><span class="title">Fast</span>-<span class="title">forward</span></span></span><br><span class="line"><span class="function"> <span class="title">fork.txt</span> | 1 +</span></span><br><span class="line"><span class="function"> 1 <span class="title">file</span> <span class="title">changed</span>, 1 <span class="title">insertion</span>(+)</span></span><br><span class="line"><span class="function"> <span class="title">create</span> <span class="title">mode</span> 100644 <span class="title">fork.txt</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function"><span class="title">Administrator</span>@<span class="title">ZhengJiaAo</span> <span class="title">MINGW64</span> /<span class="title">j</span>/<span class="title">IdeaTestProject</span>/<span class="title">GitHub</span>/<span class="title">YOUR_FORK</span> (<span class="title">master</span>)</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">push</span></span></span><br><span class="line"><span class="function"><span class="title">Enumerating</span> <span class="title">objects</span>: 4, <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Counting</span> <span class="title">objects</span>: 100% (4/4), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Delta</span> <span class="title">compression</span> <span class="title">using</span> <span class="title">up</span> <span class="title">to</span> 4 <span class="title">threads</span></span></span><br><span class="line"><span class="function"><span class="title">Compressing</span> <span class="title">objects</span>: 100% (2/2), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Writing</span> <span class="title">objects</span>: 100% (3/3), 331 <span class="title">bytes</span> | 331.00 <span class="title">KiB</span>/<span class="title">s</span>, <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Total</span> 3 (<span class="title">delta</span> 1), <span class="title">reused</span> 0 (<span class="title">delta</span> 0)</span></span><br><span class="line"><span class="function"><span class="title">remote</span>: <span class="title">Resolving</span> <span class="title">deltas</span>: 100% (1/1), <span class="title">completed</span> <span class="title">with</span> 1 <span class="title">local</span> <span class="title">object</span>.</span></span><br><span class="line"><span class="function"><span class="title">To</span> <span class="title">https</span>://<span class="title">github.com</span>/<span class="title">zhengjiaao</span>/<span class="title">YOUR_FORK.git</span></span></span><br><span class="line"><span class="function">   <span class="title">eb3614a</span>..92539<span class="title">d4</span>  <span class="title">master</span> -&gt; <span class="title">master</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function"><span class="title">Administrator</span>@<span class="title">ZhengJiaAo</span> <span class="title">MINGW64</span> /<span class="title">j</span>/<span class="title">IdeaTestProject</span>/<span class="title">GitHub</span>/<span class="title">YOUR_FORK</span> (<span class="title">master</span>)</span></span><br><span class="line"><span class="function">$</span></span><br></pre></td></tr></table></figure><p>同步后的效果图： <img src="https://upload-images.jianshu.io/upload_images/15645795-8924629b1b4caca2.png" alt="your_fork_1.png"></p><h4 id="2、将Fork出来的个人项目同步到源项目上："><a href="#2、将Fork出来的个人项目同步到源项目上：" class="headerlink" title="2、将Fork出来的个人项目同步到源项目上："></a>2、将Fork出来的个人项目同步到源项目上：</h4><p>代码：</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#拉取源项目分支</span></span><br><span class="line">git clone 源项目分支url</span><br><span class="line"></span><br><span class="line"><span class="comment">#注意：进入项目根目录 ，执行下面操作</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#查看所有远程库(remote repo)的远程url</span></span><br><span class="line">git remote -v</span><br><span class="line"></span><br><span class="line"><span class="comment">#添加Fork分支url</span></span><br><span class="line">git remote add upstream 替换成Fork分支url</span><br><span class="line"></span><br><span class="line"><span class="comment">#查看所有远程库(remote repo)的远程url</span></span><br><span class="line">git remote -v</span><br><span class="line"></span><br><span class="line"><span class="comment">#从源分支获取最新的代码</span></span><br><span class="line">git fetch upstream</span><br><span class="line"></span><br><span class="line"><span class="comment">#切换到主分支</span></span><br><span class="line">git checkout master</span><br><span class="line"></span><br><span class="line"><span class="comment">#合并本地分支和源分支,本地库和远程的github原仓库同步</span></span><br><span class="line">git merge upstream/master</span><br><span class="line"></span><br><span class="line"><span class="comment">#push到fork分支,本地的仓库提交到github</span></span><br><span class="line">git push origin master</span><br></pre></td></tr></table></figure><p>演示：</p><blockquote><p>fork后的项目的仓库(YOUR_FORK)上添加fork2文件 ，将fork2文件同步到源仓库(ORIGINAL_REPOSITORY)上</p></blockquote><p>下拉 源仓库’ORIGINAL_REPOSITORY’ 代码</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br></pre></td><td class="code"><pre><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/ORIGINAL_REPOSITORY (master)</span><br><span class="line">$ git remote -v</span><br><span class="line">origin  https://github.com/zhengjiaao/ORIGINAL_REPOSITORY.git (fetch)</span><br><span class="line">origin  https://github.com/zhengjiaao/ORIGINAL_REPOSITORY.git (push)</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/ORIGINAL_REPOSITORY (master)</span><br><span class="line">$ git remote add upstream https://github.com/zhengjiaao/YOUR_FORK.git</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/ORIGINAL_REPOSITORY (master)</span><br><span class="line">$ git remote -v</span><br><span class="line">origin  https://github.com/zhengjiaao/ORIGINAL_REPOSITORY.git (fetch)</span><br><span class="line">origin  https://github.com/zhengjiaao/ORIGINAL_REPOSITORY.git (push)</span><br><span class="line">upstream        https://github.com/zhengjiaao/YOUR_FORK.git (fetch)</span><br><span class="line">upstream        https://github.com/zhengjiaao/YOUR_FORK.git (push)</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/ORIGINAL_REPOSITORY (master)</span><br><span class="line">$ git fetch upstream</span><br><span class="line">From https://github.com/zhengjiaao/YOUR_FORK</span><br><span class="line"> * [new branch]      master     -&gt; upstream/master</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/ORIGINAL_REPOSITORY (master)</span><br><span class="line">$ git checkout master</span><br><span class="line">Already on 'master'</span><br><span class="line">Your branch is up to <span class="built_in">date</span> with 'origin/master'.</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/ORIGINAL_REPOSITORY (master)</span><br><span class="line">$ git merge upstream/master</span><br><span class="line">Already up to <span class="built_in">date</span>.</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/ORIGINAL_REPOSITORY (master)</span><br><span class="line">$ git push</span><br><span class="line">Everything up-to-<span class="built_in">date</span></span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/ORIGINAL_REPOSITORY (master)</span><br><span class="line">$ git fetch upstream</span><br><span class="line"><span class="function">remote: <span class="title">Enumerating</span> <span class="title">objects</span>: 3, <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">remote</span>: <span class="title">Counting</span> <span class="title">objects</span>: 100% (3/3), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">remote</span>: <span class="title">Compressing</span> <span class="title">objects</span>: 100% (1/1), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">remote</span>: <span class="title">Total</span> 2 (<span class="title">delta</span> 1), <span class="title">reused</span> 2 (<span class="title">delta</span> 1), <span class="title">pack</span>-<span class="title">reused</span> 0</span></span><br><span class="line"><span class="function"><span class="title">Unpacking</span> <span class="title">objects</span>: 100% (2/2), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">From</span> <span class="title">https</span>://<span class="title">github.com</span>/<span class="title">zhengjiaao</span>/<span class="title">YOUR_FORK</span></span></span><br><span class="line"><span class="function">   92539<span class="title">d4</span>..4<span class="title">a61703</span>  <span class="title">master</span>     -&gt; <span class="title">upstream</span>/<span class="title">master</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function"><span class="title">Administrator</span>@<span class="title">ZhengJiaAo</span> <span class="title">MINGW64</span> /<span class="title">j</span>/<span class="title">IdeaTestProject</span>/<span class="title">GitHub</span>/<span class="title">ORIGINAL_REPOSITORY</span> (<span class="title">master</span>)</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">checkout</span> <span class="title">master</span></span></span><br><span class="line"><span class="function"><span class="title">Already</span> <span class="title">on</span> '<span class="title">master</span>'</span></span><br><span class="line"><span class="function"><span class="title">Your</span> <span class="title">branch</span> <span class="title">is</span> <span class="title">up</span> <span class="title">to</span> <span class="title">date</span> <span class="title">with</span> '<span class="title">origin</span>/<span class="title">master</span>'.</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function"><span class="title">Administrator</span>@<span class="title">ZhengJiaAo</span> <span class="title">MINGW64</span> /<span class="title">j</span>/<span class="title">IdeaTestProject</span>/<span class="title">GitHub</span>/<span class="title">ORIGINAL_REPOSITORY</span> (<span class="title">master</span>)</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">merge</span> <span class="title">upstream</span>/<span class="title">master</span></span></span><br><span class="line"><span class="function"><span class="title">Updating</span> 92539<span class="title">d4</span>..4<span class="title">a61703</span></span></span><br><span class="line"><span class="function"><span class="title">Fast</span>-<span class="title">forward</span></span></span><br><span class="line"><span class="function"> <span class="title">fork2.txt</span> | 0</span></span><br><span class="line"><span class="function"> 1 <span class="title">file</span> <span class="title">changed</span>, 0 <span class="title">insertions</span>(+), 0 <span class="title">deletions</span>(-)</span></span><br><span class="line"><span class="function"> <span class="title">create</span> <span class="title">mode</span> 100644 <span class="title">fork2.txt</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function"><span class="title">Administrator</span>@<span class="title">ZhengJiaAo</span> <span class="title">MINGW64</span> /<span class="title">j</span>/<span class="title">IdeaTestProject</span>/<span class="title">GitHub</span>/<span class="title">ORIGINAL_REPOSITORY</span> (<span class="title">master</span>)</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">push</span></span></span><br><span class="line"><span class="function"><span class="title">Enumerating</span> <span class="title">objects</span>: 3, <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Counting</span> <span class="title">objects</span>: 100% (3/3), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Delta</span> <span class="title">compression</span> <span class="title">using</span> <span class="title">up</span> <span class="title">to</span> 4 <span class="title">threads</span></span></span><br><span class="line"><span class="function"><span class="title">Compressing</span> <span class="title">objects</span>: 100% (2/2), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Writing</span> <span class="title">objects</span>: 100% (2/2), 287 <span class="title">bytes</span> | 287.00 <span class="title">KiB</span>/<span class="title">s</span>, <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Total</span> 2 (<span class="title">delta</span> 1), <span class="title">reused</span> 0 (<span class="title">delta</span> 0)</span></span><br><span class="line"><span class="function"><span class="title">remote</span>: <span class="title">Resolving</span> <span class="title">deltas</span>: 100% (1/1), <span class="title">completed</span> <span class="title">with</span> 1 <span class="title">local</span> <span class="title">object</span>.</span></span><br><span class="line"><span class="function"><span class="title">To</span> <span class="title">https</span>://<span class="title">github.com</span>/<span class="title">zhengjiaao</span>/<span class="title">ORIGINAL_REPOSITORY.git</span></span></span><br><span class="line"><span class="function">   92539<span class="title">d4</span>..4<span class="title">a61703</span>  <span class="title">master</span> -&gt; <span class="title">master</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function"><span class="title">Administrator</span>@<span class="title">ZhengJiaAo</span> <span class="title">MINGW64</span> /<span class="title">j</span>/<span class="title">IdeaTestProject</span>/<span class="title">GitHub</span>/<span class="title">ORIGINAL_REPOSITORY</span> (<span class="title">master</span>)</span></span><br><span class="line"><span class="function">$</span></span><br></pre></td></tr></table></figure><p>同步后的效果图： <img src="https://upload-images.jianshu.io/upload_images/15645795-2b9859fa568b7ece.png" alt="original_repository_1.png"></p><h3 id="方式二：分别git-push到A仓库和B仓库"><a href="#方式二：分别git-push到A仓库和B仓库" class="headerlink" title="方式二：分别git push到A仓库和B仓库"></a>方式二：分别git push到A仓库和B仓库</h3><h4 id="1、将A仓库代码同步到Fork出来的B仓库上："><a href="#1、将A仓库代码同步到Fork出来的B仓库上：" class="headerlink" title="1、将A仓库代码同步到Fork出来的B仓库上："></a>1、将A仓库代码同步到Fork出来的B仓库上：</h4><p>代码：</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#拉取Fork出来的分支</span></span><br><span class="line">git clone Fork的分支url</span><br><span class="line"></span><br><span class="line"><span class="comment">#注意：进入项目根目录 ，执行下面操作</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#查看所有远程库(remote repo)的远程url</span></span><br><span class="line">git remote -v</span><br><span class="line"></span><br><span class="line"><span class="comment">#添加源分支url</span></span><br><span class="line">git remote add upstream 替换成源项目url</span><br><span class="line"></span><br><span class="line"><span class="comment">#查看所有远程库(remote repo)的远程url</span></span><br><span class="line">git remote -v</span><br><span class="line"></span><br><span class="line"><span class="comment">#从源分支获取最新的代码</span></span><br><span class="line">git fetch upstream</span><br><span class="line"></span><br><span class="line"><span class="comment">#切换到主分支</span></span><br><span class="line">git checkout master</span><br><span class="line"></span><br><span class="line"><span class="comment">#合并本地分支和源分支,本地库和远程的github原仓库同步</span></span><br><span class="line">git merge upstream/master</span><br><span class="line"></span><br><span class="line"><span class="comment">#push到fork分支,本地的仓库提交到github的B仓库上</span></span><br><span class="line">git push</span><br><span class="line"></span><br><span class="line"><span class="comment">#push到A远程仓库上</span></span><br><span class="line">git push upstream master</span><br></pre></td></tr></table></figure><p>演示：</p><blockquote><p>源项目的仓库(ORIGINAL_REPOSITORY)添加fork文件 ，将fork文件同步到fork后的项目仓库(YOUR_FORK)上</p></blockquote><p>下拉 fork后的仓库 ‘YOUR_FORK’ 代码</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git remote -v</span><br><span class="line">origin  https://github.com/zhengjiaao/YOUR_FORK.git (fetch)</span><br><span class="line">origin  https://github.com/zhengjiaao/YOUR_FORK.git (push)</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git remote add upstream https://github.com/zhengjiaao/ORIGINAL_REPOSITORY.git</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git remote -v</span><br><span class="line">origin  https://github.com/zhengjiaao/YOUR_FORK.git (fetch)</span><br><span class="line">origin  https://github.com/zhengjiaao/YOUR_FORK.git (push)</span><br><span class="line">upstream        https://github.com/zhengjiaao/ORIGINAL_REPOSITORY.git (fetch)</span><br><span class="line">upstream        https://github.com/zhengjiaao/ORIGINAL_REPOSITORY.git (push)</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git fetch upstream</span><br><span class="line">From https://github.com/zhengjiaao/ORIGINAL_REPOSITORY</span><br><span class="line"> * [new branch]      master     -&gt; upstream/master</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git checkout master</span><br><span class="line">Already on 'master'</span><br><span class="line">Your branch is up to <span class="built_in">date</span> with 'origin/master'.</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git merge upstream/master</span><br><span class="line">Already up to <span class="built_in">date</span>.</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git push origin master</span><br><span class="line">Everything up-to-<span class="built_in">date</span></span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git push</span><br><span class="line">Everything up-to-<span class="built_in">date</span></span><br></pre></td></tr></table></figure><p>修改B本地仓库fork文件 ，将fork文件同步到B远程仓库和A远程仓库：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git add .</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git commit -m "your_fork 修改fork文件"</span><br><span class="line">[master <span class="number">0</span>b44e55] your_fork 修改fork文件</span><br><span class="line"> <span class="number">1</span> file changed, <span class="number">8</span> insertions(+), <span class="number">1</span> deletion(-)</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git push</span><br><span class="line">Enumerating objects: <span class="number">5</span>, done.</span><br><span class="line">Counting objects: <span class="number">100</span>% (<span class="number">5</span>/<span class="number">5</span>), done.</span><br><span class="line">Delta compression using up to <span class="number">4</span> threads</span><br><span class="line">Compressing objects: <span class="number">100</span>% (<span class="number">3</span>/<span class="number">3</span>), done.</span><br><span class="line">Writing objects: <span class="number">100</span>% (<span class="number">3</span>/<span class="number">3</span>), <span class="number">371</span> bytes | <span class="number">371</span>.<span class="number">00</span> KiB/s, done.</span><br><span class="line">Total <span class="number">3</span> (delta <span class="number">1</span>), reused <span class="number">0</span> (delta <span class="number">0</span>)</span><br><span class="line"><span class="function">remote: <span class="title">Resolving</span> <span class="title">deltas</span>: 100% (1/1), <span class="title">completed</span> <span class="title">with</span> 1 <span class="title">local</span> <span class="title">object</span>.</span></span><br><span class="line"><span class="function"><span class="title">To</span> <span class="title">https</span>://<span class="title">github.com</span>/<span class="title">zhengjiaao</span>/<span class="title">YOUR_FORK.git</span></span></span><br><span class="line"><span class="function">   4<span class="title">a61703</span>..0<span class="title">b44e55</span>  <span class="title">master</span> -&gt; <span class="title">master</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function"><span class="title">Administrator</span>@<span class="title">ZhengJiaAo</span> <span class="title">MINGW64</span> /<span class="title">j</span>/<span class="title">IdeaTestProject</span>/<span class="title">GitHub</span>/<span class="title">YOUR_FORK</span> (<span class="title">master</span>)</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">push</span> <span class="title">upstream</span> <span class="title">master</span></span></span><br><span class="line"><span class="function"><span class="title">Enumerating</span> <span class="title">objects</span>: 5, <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Counting</span> <span class="title">objects</span>: 100% (5/5), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Delta</span> <span class="title">compression</span> <span class="title">using</span> <span class="title">up</span> <span class="title">to</span> 4 <span class="title">threads</span></span></span><br><span class="line"><span class="function"><span class="title">Compressing</span> <span class="title">objects</span>: 100% (3/3), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Writing</span> <span class="title">objects</span>: 100% (3/3), 371 <span class="title">bytes</span> | 185.00 <span class="title">KiB</span>/<span class="title">s</span>, <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Total</span> 3 (<span class="title">delta</span> 1), <span class="title">reused</span> 0 (<span class="title">delta</span> 0)</span></span><br><span class="line"><span class="function"><span class="title">remote</span>: <span class="title">Resolving</span> <span class="title">deltas</span>: 100% (1/1), <span class="title">completed</span> <span class="title">with</span> 1 <span class="title">local</span> <span class="title">object</span>.</span></span><br><span class="line"><span class="function"><span class="title">To</span> <span class="title">https</span>://<span class="title">github.com</span>/<span class="title">zhengjiaao</span>/<span class="title">ORIGINAL_REPOSITORY.git</span></span></span><br><span class="line"><span class="function">   4<span class="title">a61703</span>..0<span class="title">b44e55</span>  <span class="title">master</span> -&gt; <span class="title">master</span></span></span><br></pre></td></tr></table></figure><blockquote><p>可以看出我第一次是直接git push ，没有指定远程库名称 ，默认推送到了gitosc中 ，开始还以为一次性推送到了2个服务器呢 ，剩下的github需要指定名称推送</p></blockquote><p><strong>反过来 ，也可以在将出来的ForkB仓库代码同步到A仓库上</strong></p><h3 id="方式三：git-push-一次性推送到A和B仓库上-推荐"><a href="#方式三：git-push-一次性推送到A和B仓库上-推荐" class="headerlink" title="方式三：git push 一次性推送到A和B仓库上(推荐)"></a>方式三：git push 一次性推送到A和B仓库上(推荐)</h3><p>找到项目根目录下.git/config文件 ，可以看到添加的有origin和upstream两个仓库。<br>config文件：</p><figure class="highlight py"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">[core]</span><br><span class="line">	repositoryformatversion = <span class="number">0</span></span><br><span class="line">	filemode = false</span><br><span class="line">	bare = false</span><br><span class="line">	logallrefupdates = true</span><br><span class="line">	symlinks = false</span><br><span class="line">	ignorecase = true</span><br><span class="line">[remote <span class="string">"origin"</span>]</span><br><span class="line">	url = https://github.com/zhengjiaao/YOUR_FORK.git</span><br><span class="line">	fetch = +refs/heads/*:refs/remotes/origin/*</span><br><span class="line">[branch <span class="string">"master"</span>]</span><br><span class="line">	remote = origin</span><br><span class="line">	merge = refs/heads/master</span><br><span class="line">[remote <span class="string">"upstream"</span>]</span><br><span class="line">	url = https://github.com/zhengjiaao/ORIGINAL_REPOSITORY.git</span><br><span class="line">	fetch = +refs/heads/*:refs/remotes/upstream/*</span><br></pre></td></tr></table></figure><p>移除仓库：git remote rm 仓库名称</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git remote rm origin</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git remote rm upstream</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git remote add all https://github.com/zhengjiaao/YOUR_FORK.git</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git remote <span class="built_in">set</span>-url --add all https://github.com/zhengjiaao/ORIGINAL_REPOSITORY.git</span><br></pre></td></tr></table></figure><p>config文件：</p><figure class="highlight py"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">[core]</span><br><span class="line">	repositoryformatversion = <span class="number">0</span></span><br><span class="line">	filemode = false</span><br><span class="line">	bare = false</span><br><span class="line">	logallrefupdates = true</span><br><span class="line">	symlinks = false</span><br><span class="line">	ignorecase = true</span><br><span class="line">[remote <span class="string">"all"</span>]</span><br><span class="line">	url = https://github.com/zhengjiaao/YOUR_FORK.git</span><br><span class="line">	fetch = +refs/heads/*:refs/remotes/all/*</span><br><span class="line">	url = https://github.com/zhengjiaao/ORIGINAL_REPOSITORY.git</span><br></pre></td></tr></table></figure><p>修改fork文件内容 ，测试一次性提交到两个仓库</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git add .</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git commit -m "测试git push all --all"</span><br><span class="line">[master <span class="number">069</span>ffcf] 测试git push all --all</span><br><span class="line"> <span class="number">1</span> file changed, <span class="number">1</span> insertion(+), <span class="number">1</span> deletion(-)</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git push all -all</span><br><span class="line"><span class="function">error: <span class="title">did</span> <span class="title">you</span> <span class="title">mean</span> `--<span class="title">all</span>` (<span class="title">with</span> <span class="title">two</span> <span class="title">dashes</span> ?)</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function"><span class="title">Administrator</span>@<span class="title">ZhengJiaAo</span> <span class="title">MINGW64</span> /<span class="title">j</span>/<span class="title">IdeaTestProject</span>/<span class="title">GitHub</span>/<span class="title">YOUR_FORK</span> (<span class="title">master</span>)</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">push</span> <span class="title">all</span> --<span class="title">all</span></span></span><br><span class="line"><span class="function"><span class="title">Enumerating</span> <span class="title">objects</span>: 5, <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Counting</span> <span class="title">objects</span>: 100% (5/5), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Delta</span> <span class="title">compression</span> <span class="title">using</span> <span class="title">up</span> <span class="title">to</span> 4 <span class="title">threads</span></span></span><br><span class="line"><span class="function"><span class="title">Compressing</span> <span class="title">objects</span>: 100% (3/3), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Writing</span> <span class="title">objects</span>: 100% (3/3), 318 <span class="title">bytes</span> | 318.00 <span class="title">KiB</span>/<span class="title">s</span>, <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Total</span> 3 (<span class="title">delta</span> 2), <span class="title">reused</span> 0 (<span class="title">delta</span> 0)</span></span><br><span class="line"><span class="function"><span class="title">remote</span>: <span class="title">Resolving</span> <span class="title">deltas</span>: 100% (2/2), <span class="title">completed</span> <span class="title">with</span> 2 <span class="title">local</span> <span class="title">objects</span>.</span></span><br><span class="line"><span class="function"><span class="title">To</span> <span class="title">https</span>://<span class="title">github.com</span>/<span class="title">zhengjiaao</span>/<span class="title">YOUR_FORK.git</span></span></span><br><span class="line"><span class="function">   0<span class="title">b44e55</span>..069<span class="title">ffcf</span>  <span class="title">master</span> -&gt; <span class="title">master</span></span></span><br><span class="line"><span class="function"><span class="title">Enumerating</span> <span class="title">objects</span>: 5, <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Counting</span> <span class="title">objects</span>: 100% (5/5), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Delta</span> <span class="title">compression</span> <span class="title">using</span> <span class="title">up</span> <span class="title">to</span> 4 <span class="title">threads</span></span></span><br><span class="line"><span class="function"><span class="title">Compressing</span> <span class="title">objects</span>: 100% (3/3), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Writing</span> <span class="title">objects</span>: 100% (3/3), 318 <span class="title">bytes</span> | 318.00 <span class="title">KiB</span>/<span class="title">s</span>, <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Total</span> 3 (<span class="title">delta</span> 2), <span class="title">reused</span> 0 (<span class="title">delta</span> 0)</span></span><br><span class="line"><span class="function"><span class="title">remote</span>: <span class="title">Resolving</span> <span class="title">deltas</span>: 100% (2/2), <span class="title">completed</span> <span class="title">with</span> 2 <span class="title">local</span> <span class="title">objects</span>.</span></span><br><span class="line"><span class="function"><span class="title">To</span> <span class="title">https</span>://<span class="title">github.com</span>/<span class="title">zhengjiaao</span>/<span class="title">ORIGINAL_REPOSITORY.git</span></span></span><br><span class="line"><span class="function">   0<span class="title">b44e55</span>..069<span class="title">ffcf</span>  <span class="title">master</span> -&gt; <span class="title">master</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function"><span class="title">Administrator</span>@<span class="title">ZhengJiaAo</span> <span class="title">MINGW64</span> /<span class="title">j</span>/<span class="title">IdeaTestProject</span>/<span class="title">GitHub</span>/<span class="title">YOUR_FORK</span> (<span class="title">master</span>)</span></span><br><span class="line"><span class="function">$</span></span><br></pre></td></tr></table></figure><p>提交成功!–&gt;去github上查看两个仓库都有提交的信息。</p><h3 id="方式四：一次性推送到A和B仓库上-修改-git-config配置文件"><a href="#方式四：一次性推送到A和B仓库上-修改-git-config配置文件" class="headerlink" title="方式四：一次性推送到A和B仓库上(修改.git/config配置文件)"></a>方式四：一次性推送到A和B仓库上(修改.git/config配置文件)</h3><p>查看.git/config配置文件:</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">[core]</span><br><span class="line">	repositoryformatversion &#x3D; 0</span><br><span class="line">	filemode &#x3D; false</span><br><span class="line">	bare &#x3D; false</span><br><span class="line">	logallrefupdates &#x3D; true</span><br><span class="line">	symlinks &#x3D; false</span><br><span class="line">	ignorecase &#x3D; true</span><br><span class="line">[remote &quot;all&quot;]</span><br><span class="line">	url &#x3D; https:&#x2F;&#x2F;github.com&#x2F;zhengjiaao&#x2F;YOUR_FORK.git</span><br><span class="line">	fetch &#x3D; +refs&#x2F;heads&#x2F;*:refs&#x2F;remotes&#x2F;all&#x2F;*</span><br><span class="line">	url &#x3D; https:&#x2F;&#x2F;github.com&#x2F;zhengjiaao&#x2F;ORIGINAL_REPOSITORY.git</span><br></pre></td></tr></table></figure><p>删除all</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git remote rm all</span><br></pre></td></tr></table></figure><p>查看.git/config配置文件:</p><figure class="highlight py"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">[core]</span><br><span class="line">	repositoryformatversion = <span class="number">0</span></span><br><span class="line">	filemode = false</span><br><span class="line">	bare = false</span><br><span class="line">	logallrefupdates = true</span><br><span class="line">	symlinks = false</span><br><span class="line">	ignorecase = true</span><br></pre></td></tr></table></figure><p>直接修改.git/config配置文件：</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">[core]</span><br><span class="line">	repositoryformatversion &#x3D; 0</span><br><span class="line">	filemode &#x3D; false</span><br><span class="line">	bare &#x3D; false</span><br><span class="line">	logallrefupdates &#x3D; true</span><br><span class="line">	symlinks &#x3D; false</span><br><span class="line">	ignorecase &#x3D; true</span><br><span class="line">[remote &quot;all&quot;]</span><br><span class="line">    	url &#x3D; https:&#x2F;&#x2F;github.com&#x2F;zhengjiaao&#x2F;YOUR_FORK.git</span><br><span class="line">    	url &#x3D; https:&#x2F;&#x2F;github.com&#x2F;zhengjiaao&#x2F;ORIGINAL_REPOSITORY.git</span><br></pre></td></tr></table></figure><p>修改fork文件内容 ，测试一次性提交到两个仓库</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git remote rm all</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git add .</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git commit -m "测试修改config配置文件"</span><br><span class="line">[master e3c0277] 测试修改config配置文件</span><br><span class="line"> <span class="number">1</span> file changed, <span class="number">1</span> insertion(+)</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/YOUR_FORK (master)</span><br><span class="line">$ git push all --all</span><br><span class="line">Enumerating objects: <span class="number">5</span>, done.</span><br><span class="line">Counting objects: <span class="number">100</span>% (<span class="number">5</span>/<span class="number">5</span>), done.</span><br><span class="line">Delta compression using up to <span class="number">4</span> threads</span><br><span class="line">Compressing objects: <span class="number">100</span>% (<span class="number">3</span>/<span class="number">3</span>), done.</span><br><span class="line">Writing objects: <span class="number">100</span>% (<span class="number">3</span>/<span class="number">3</span>), <span class="number">354</span> bytes | <span class="number">354</span>.<span class="number">00</span> KiB/s, done.</span><br><span class="line">Total <span class="number">3</span> (delta <span class="number">2</span>), reused <span class="number">0</span> (delta <span class="number">0</span>)</span><br><span class="line"><span class="function">remote: <span class="title">Resolving</span> <span class="title">deltas</span>: 100% (2/2), <span class="title">completed</span> <span class="title">with</span> 2 <span class="title">local</span> <span class="title">objects</span>.</span></span><br><span class="line"><span class="function"><span class="title">To</span> <span class="title">https</span>://<span class="title">github.com</span>/<span class="title">zhengjiaao</span>/<span class="title">YOUR_FORK.git</span></span></span><br><span class="line"><span class="function">   069<span class="title">ffcf</span>..<span class="title">e3c0277</span>  <span class="title">master</span> -&gt; <span class="title">master</span></span></span><br><span class="line"><span class="function"><span class="title">Enumerating</span> <span class="title">objects</span>: 5, <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Counting</span> <span class="title">objects</span>: 100% (5/5), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Delta</span> <span class="title">compression</span> <span class="title">using</span> <span class="title">up</span> <span class="title">to</span> 4 <span class="title">threads</span></span></span><br><span class="line"><span class="function"><span class="title">Compressing</span> <span class="title">objects</span>: 100% (3/3), <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Writing</span> <span class="title">objects</span>: 100% (3/3), 354 <span class="title">bytes</span> | 354.00 <span class="title">KiB</span>/<span class="title">s</span>, <span class="title">done</span>.</span></span><br><span class="line"><span class="function"><span class="title">Total</span> 3 (<span class="title">delta</span> 2), <span class="title">reused</span> 0 (<span class="title">delta</span> 0)</span></span><br><span class="line"><span class="function"><span class="title">remote</span>: <span class="title">Resolving</span> <span class="title">deltas</span>: 100% (2/2), <span class="title">completed</span> <span class="title">with</span> 2 <span class="title">local</span> <span class="title">objects</span>.</span></span><br><span class="line"><span class="function"><span class="title">To</span> <span class="title">https</span>://<span class="title">github.com</span>/<span class="title">zhengjiaao</span>/<span class="title">ORIGINAL_REPOSITORY.git</span></span></span><br><span class="line"><span class="function">   069<span class="title">ffcf</span>..<span class="title">e3c0277</span>  <span class="title">master</span> -&gt; <span class="title">master</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function"><span class="title">Administrator</span>@<span class="title">ZhengJiaAo</span> <span class="title">MINGW64</span> /<span class="title">j</span>/<span class="title">IdeaTestProject</span>/<span class="title">GitHub</span>/<span class="title">YOUR_FORK</span> (<span class="title">master</span>)</span></span><br><span class="line"><span class="function">$</span></span><br></pre></td></tr></table></figure><p>上传成功!</p><h2 id="二、仓库A和仓库B只同步部分文件"><a href="#二、仓库A和仓库B只同步部分文件" class="headerlink" title="二、仓库A和仓库B只同步部分文件"></a>二、仓库A和仓库B只同步部分文件</h2><p>比如仓库A和仓库B ，B是从A上面fork出来的 ，然后分别在A,B进行了开发:</p><blockquote><p>1.这个时候想把A,B之间的修改相互同步<br>2.如果A修改了10个 ，只想同步5个到B ，怎么操作<br>3.B修改了10个 ，想同步3个到A ，怎么操作</p></blockquote><p>A远程仓库修改了10个 ，只想同步5个到远程B仓库</p><p>方式一：10个文件都上传到A的远程仓库 ，然后同步5个指定文件到B的远程仓库</p><p>参考：下方的 <strong>三、git克隆或下载一个A仓库单个文件夹 ，并push到B仓库里</strong></p><p>方式二：10个文件只上传5个指定的文件上传到远程A上 ，然后远A同步到远程B上</p><p>参考：下方的 <strong>三、git克隆或下载一个A仓库单个文件夹 ，并push到B仓库里</strong></p><h2 id="三、git克隆或下载一个A仓库单个文件夹-，并push到B仓库里"><a href="#三、git克隆或下载一个A仓库单个文件夹-，并push到B仓库里" class="headerlink" title="三、git克隆或下载一个A仓库单个文件夹 ，并push到B仓库里"></a>三、git克隆或下载一个A仓库单个文件夹 ，并push到B仓库里</h2><p>仓库（YOUR_FORK）：<a href="https://github.com/zhengjiaao/YOUR_FORK.git" target="_blank" rel="noopener">https://github.com/zhengjiaao/YOUR_FORK.git</a></p><blockquote><p>克隆文件：’YOUR_FORK/fork.txt’ 或 克隆文件夹：’YOUR_FORK/文件夹/*’ 是克隆’文件夹’下的所有文件</p><p>注意：.git/info/sparse-checkout文件每一行是一个文件或文件夹</p><p>使用：echo ‘fork.txt’ &gt;&gt; .git/info/sparse-checkout</p><p>echo ‘文件夹/*’ &gt;&gt; .git/info/sparse-checkout</p></blockquote><p>现在想只克隆YOUR_FORK/fork.txt文件 ，本地新建一个文件test文件夹：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/test (master)</span><br><span class="line">$ git init</span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/test (master)</span><br><span class="line">$ git config core.sparsecheckout true</span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/test (master)</span><br><span class="line">$ <span class="built_in">echo</span> 'fork.txt' &gt;&gt; .git/info/sparse-checkout</span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/test (master)</span><br><span class="line">$ git remote add origin https://github.com/zhengjiaao/YOUR_FORK.git</span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/test (master)</span><br><span class="line">$ git pull origin master</span><br></pre></td></tr></table></figure><p>效果： <img src="https://upload-images.jianshu.io/upload_images/15645795-8ba6a8c2767864f5.png" alt="spatse-checkout.png"></p><p>克隆一个文件成功!</p><p>下面将这个fork.txt文件git push 到自己的github仓库上</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br></pre></td><td class="code"><pre><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/test (master)</span><br><span class="line">$ git remote -v</span><br><span class="line">origin  https://github.com/zhengjiaao/YOUR_FORK.git (fetch)</span><br><span class="line">origin  https://github.com/zhengjiaao/YOUR_FORK.git (push)</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/test (master)</span><br><span class="line">$ git remote add upstream https://github.com/zhengjiaao/ORIGINAL_REPOSITORY.git</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/test (master)</span><br><span class="line">$ git remote -v</span><br><span class="line">origin  https://github.com/zhengjiaao/YOUR_FORK.git (fetch)</span><br><span class="line">origin  https://github.com/zhengjiaao/YOUR_FORK.git (push)</span><br><span class="line">upstream        https://github.com/zhengjiaao/ORIGINAL_REPOSITORY.git (fetch)</span><br><span class="line">upstream        https://github.com/zhengjiaao/ORIGINAL_REPOSITORY.git (push)</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/test (master)</span><br><span class="line">$ git fetch upstream</span><br><span class="line">From https://github.com/zhengjiaao/ORIGINAL_REPOSITORY</span><br><span class="line"> * [new branch]      master     -&gt; upstream/master</span><br><span class="line"> </span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/test (master)</span><br><span class="line">$ git fetch upstream</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/test (master)</span><br><span class="line">$ git checkout master</span><br><span class="line">Already on 'master'</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/test (master)</span><br><span class="line">$ git merge upstream/master</span><br><span class="line">Already up to <span class="built_in">date</span>.</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/test (master)</span><br><span class="line">$ git push upstream master</span><br><span class="line">Everything up-to-<span class="built_in">date</span></span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/test (master)</span><br><span class="line">$ git checkout master</span><br><span class="line">Already on 'master'</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/test (master)</span><br><span class="line">$ git merge upstream/master</span><br><span class="line">Already up to <span class="built_in">date</span>.</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/test (master)</span><br><span class="line">$ git pull origin master</span><br><span class="line">From https://github.com/zhengjiaao/YOUR_FORK</span><br><span class="line"> * branch            master     -&gt; FETCH_HEAD</span><br><span class="line">Updating e3c0277..b407bf8</span><br><span class="line">Fast-forward</span><br><span class="line"> fork.txt  | <span class="number">1</span> +</span><br><span class="line"> fork2.txt | <span class="number">3</span> +++</span><br><span class="line"> <span class="number">2</span> files changed, <span class="number">4</span> insertions(+)</span><br><span class="line"></span><br><span class="line">Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/test (master)</span><br><span class="line">$ git push upstream master</span><br><span class="line">Enumerating objects: <span class="number">7</span>, done.</span><br><span class="line">Counting objects: <span class="number">100</span>% (<span class="number">7</span>/<span class="number">7</span>), done.</span><br><span class="line">Delta compression using up to <span class="number">4</span> threads</span><br><span class="line">Compressing objects: <span class="number">100</span>% (<span class="number">3</span>/<span class="number">3</span>), done.</span><br><span class="line">Writing objects: <span class="number">100</span>% (<span class="number">4</span>/<span class="number">4</span>), <span class="number">459</span> bytes | <span class="number">229</span>.<span class="number">00</span> KiB/s, done.</span><br><span class="line">Total <span class="number">4</span> (delta <span class="number">2</span>), reused <span class="number">0</span> (delta <span class="number">0</span>)</span><br><span class="line"><span class="function">remote: <span class="title">Resolving</span> <span class="title">deltas</span>: 100% (2/2), <span class="title">completed</span> <span class="title">with</span> 2 <span class="title">local</span> <span class="title">objects</span>.</span></span><br><span class="line"><span class="function"><span class="title">To</span> <span class="title">https</span>://<span class="title">github.com</span>/<span class="title">zhengjiaao</span>/<span class="title">ORIGINAL_REPOSITORY.git</span></span></span><br><span class="line"><span class="function">   <span class="title">e3c0277</span>..<span class="title">b407bf8</span>  <span class="title">master</span> -&gt; <span class="title">master</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function"><span class="title">Administrator</span>@<span class="title">ZhengJiaAo</span> <span class="title">MINGW64</span> /<span class="title">j</span>/<span class="title">IdeaTestProject</span>/<span class="title">GitHub</span>/<span class="title">test</span> (<span class="title">master</span>)</span></span><br><span class="line"><span class="function">$</span></span><br></pre></td></tr></table></figure><blockquote><p>注意：第一次克隆了文件 ，如果还想再克隆其它的文件 ，则需要克隆的项目有提交记录 ，不然无法再次克隆成功!<br>提示：<br>Administrator@ZhengJiaAo MINGW64 /j/IdeaTestProject/GitHub/test (master)<br>$ git pull origin master<br>From <a href="https://github.com/zhengjiaao/YOUR_FORK" target="_blank" rel="noopener">https://github.com/zhengjiaao/YOUR_FORK</a><br>branch master -&gt; FETCH_HEAD<br>Already up to date.</p></blockquote><h2 id="四、仓库源A和Fork的仓库B-只同步部分文件"><a href="#四、仓库源A和Fork的仓库B-只同步部分文件" class="headerlink" title="四、仓库源A和Fork的仓库B 只同步部分文件"></a>四、仓库源A和Fork的仓库B 只同步部分文件</h2><blockquote><p><strong>说明：A远程仓库和B远程仓库的分支 ，github：B仓库是从A仓库Fork出来的 ，且删除了B仓库的dev分支</strong></p><p>A远程仓库所有分支:<br>remotes/origin/dev<br>remotes/origin/master<br>remotes/origin/pro</p><p>B远程仓库所有分支:<br>remotes/origin/master<br>remotes/origin/pro</p></blockquote><h5 id="假如：A远程仓库的pro分支commit-10次-，B远程仓库pro分支commit-5次"><a href="#假如：A远程仓库的pro分支commit-10次-，B远程仓库pro分支commit-5次" class="headerlink" title="假如：A远程仓库的pro分支commit 10次 ，B远程仓库pro分支commit 5次"></a>假如：A远程仓库的pro分支commit 10次 ，B远程仓库pro分支commit 5次</h5><blockquote><p>要求:<br>1、A远程仓库的commit 第2次提交的内容 同步到B远程仓库<br>2、B远程仓库的第3次commit内容提交到 A远程仓库中</p></blockquote><h5 id="思路：创建本地仓库-，且与多个远程仓库关联-，再关联远程分支"><a href="#思路：创建本地仓库-，且与多个远程仓库关联-，再关联远程分支" class="headerlink" title="思路：创建本地仓库 ，且与多个远程仓库关联 ，再关联远程分支"></a>思路：创建本地仓库 ，且与多个远程仓库关联 ，再关联远程分支</h5><p>方式：创建一个本地仓库YOUR_FORK_AB_pro ，git init初始化并分别关联’B远程仓库的pro分支和关联A远程仓库的pro分支’ ，B_pro,A_pro</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">#初始化your_fork_AB_pro本地仓库</span><br><span class="line">$ git init</span><br><span class="line">#关联多个远程仓库</span><br><span class="line">$ git remote add A https://github.com/zhengjiaao/YOUR_FORK.git</span><br><span class="line">$ git remote add B https://github.com/zhengjiaao/YOUR_FORK_pro.git</span><br><span class="line"></span><br><span class="line">#查看本地仓库关联的所有远程仓库地址</span><br><span class="line">$ git remote -v</span><br><span class="line"></span><br><span class="line">#更新远程仓库数据信息到本地仓库your_fork_AB_pro ，不是将远程仓库代码下拉到本地</span><br><span class="line">$ git fetch A pro</span><br><span class="line">$ git fetch B pro</span><br><span class="line"></span><br><span class="line">#分别创建本地分支且关联的远程分支 A_pro 和 B_pro</span><br><span class="line">$ git checkout -b A_pro A/pro</span><br><span class="line">$ git checkout -b B_pro B/pro</span><br><span class="line"></span><br><span class="line">#查看所有分支</span><br><span class="line">$ git branch -a</span><br><span class="line">  A_pro</span><br><span class="line">* B_pro</span><br><span class="line">  remotes/A/dev</span><br><span class="line">  remotes/A/master</span><br><span class="line">  remotes/A/pro</span><br><span class="line">  remotes/B/pro</span><br></pre></td></tr></table></figure><blockquote><p>现在本地仓库有两个分支A_pro和B_pro ，我们就可以对这两个分支进行操作 ，例如：合并操作–&gt;合并某次的commit ，合并某个文件或文件夹等</p></blockquote><h5 id="例如：合并本地分支的某个文件或文件夹"><a href="#例如：合并本地分支的某个文件或文件夹" class="headerlink" title="例如：合并本地分支的某个文件或文件夹"></a>例如：合并本地分支的某个文件或文件夹</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">#合并本地分支的某个文件或文件夹</span><br><span class="line"></span><br><span class="line">#如：想要将分支B_pro下public文件下所有文件和view下index.html文件合并到分支A_pro</span><br><span class="line">#首先切换到A仓库的分支A_pro</span><br><span class="line">$ git checkout A_pro</span><br><span class="line">#合并B仓库的B_pro分支 ， 注意：因为public下可能有多层目录 ，所有不能使用public&#x2F;*</span><br><span class="line">$ git checkout B_pro public&#x2F;** view&#x2F;index.html</span><br></pre></td></tr></table></figure><h5 id="例如：合并某次的commit提交内容"><a href="#例如：合并某次的commit提交内容" class="headerlink" title="例如：合并某次的commit提交内容"></a>例如：合并某次的commit提交内容</h5><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">#合并某次的commit提交内容</span><br><span class="line"></span><br><span class="line">#例如：将A_pro分支某次commit提交的内容合并到B_pro</span><br><span class="line">#切换到A_pro分支 </span><br><span class="line">$ git checkout A_pro</span><br><span class="line">#查看A_pro分支 commit提交的日志</span><br><span class="line">$ git log</span><br><span class="line">commit <span class="number">68</span>cfab5b9c4b536b6d42117d476308685fbef7ad (HEAD -&gt; A_pro, A/pro)</span><br><span class="line"><span class="function">Author: <span class="title">Zhengjiaao</span> &lt;1263598336@<span class="title">qq.com</span>&gt;</span></span><br><span class="line"><span class="function"><span class="title">Date</span>:   <span class="title">Tue</span> <span class="title">Oct</span> 15 09:53:16 2019 +0800</span></span><br><span class="line"><span class="function">    <span class="title">your_fork</span>:新增<span class="title">fork10</span>文件</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function"><span class="title">commit</span> 3<span class="title">c03d1c376ccc8c58d1f232c5e0f57cdeba8df53</span></span></span><br><span class="line"><span class="function"><span class="title">Author</span>: <span class="title">Zhengjiaao</span> &lt;1263598336@<span class="title">qq.com</span>&gt;</span></span><br><span class="line"><span class="function"><span class="title">Date</span>:   <span class="title">Tue</span> <span class="title">Oct</span> 15 09:52:46 2019 +0800</span></span><br><span class="line"><span class="function">    <span class="title">your_fork</span>:新增<span class="title">fork9</span>文件</span></span><br><span class="line"><span class="function">    </span></span><br><span class="line"><span class="function"><span class="title">commit</span> <span class="title">a1ad40b91d87e4ec30c869e404fabca56a7e47ea</span></span></span><br><span class="line"><span class="function"><span class="title">Author</span>: <span class="title">Zhengjiaao</span> &lt;1263598336@<span class="title">qq.com</span>&gt;</span></span><br><span class="line"><span class="function"><span class="title">Date</span>:   <span class="title">Tue</span> <span class="title">Oct</span> 15 09:52:23 2019 +0800</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">    <span class="title">your_fork</span>:新增<span class="title">fork8</span>文件</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#退出日志 英文状态下按<span class="title">Q</span></span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">#将<span class="title">A_pro</span>分支 ‘新增<span class="title">fork9</span>文件’这次<span class="title">commit</span>提交的内容 合并到<span class="title">B_pro</span></span></span><br><span class="line"><span class="function">#切换到<span class="title">B_pro</span>分支 </span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">checkout</span> <span class="title">B_pro</span></span></span><br><span class="line"><span class="function">#选择<span class="title">A_pro</span>分支 ‘新增<span class="title">fork9</span>文件’这次<span class="title">commit</span>的<span class="title">id</span>合并到<span class="title">B_pro</span>分支上,当然不会把<span class="title">A_pro</span>分支 ‘新增<span class="title">fork9</span>文件’<span class="title">commit</span>之前的 ，也就是‘新增<span class="title">fork8</span>文件’这次<span class="title">commit</span>所提交的文件包含在内 ，仅合并"新增<span class="title">fork9</span>文件"的<span class="title">commit</span>。</span></span><br><span class="line"><span class="function">$ <span class="title">git</span> <span class="title">cherry</span>-<span class="title">pick</span> 3<span class="title">c03d1c376ccc8c58d1f232c5e0f57cdeba8df53</span></span></span><br></pre></td></tr></table></figure><p>B仓库的B_pro分支合并A仓库的A_pro分支某次commit的效果图： <img src="https://upload-images.jianshu.io/upload_images/15645795-76f280ef91be6375.png" alt="git合并分支效果.png"></p></div><div class="popular-posts-header"><p style="font-size:18px;color:red;margin:0 0 5px 0">相关文章推荐：</p></div><ul class="popular-posts"><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\832089102.html" rel="bookmark">Git-下拉和上传项目</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\2127647912.html" rel="bookmark">Git-远程仓库及分支管理</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\2439716409.html" rel="bookmark">GitHub上创建自己的Maven仓库并引用</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\3963925067.html" rel="bookmark">Github-添加ssh-keys</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\3395771604.html" rel="bookmark">Git使用</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\39002084.html" rel="bookmark">git-同步远程仓库A和远程仓库B</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\426039077.html" rel="bookmark">git-stash-用法</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\3364886539.html" rel="bookmark">gitlab排查问题及下拉上传</a></div></li></ul><div><div style="text-align:center;color:#ccc;font-size:14px">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div></div><div class="reward-container"><div><p style="font-size:14px;color:#34495e;margin:0 0 5px 0">赞赏一下吧～ 还可以关注公众号订阅最新内容</p></div><button disable="enable" onclick="var qr = document.getElementById(&quot;qr&quot;); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">打赏</button><div id="qr" style="display:none"><div style="display:inline-block"><img src="/my-images/WeChat.png" alt="宇宙小神特别萌 微信支付"><p>微信支付</p></div><div style="display:inline-block"><img src="/my-images/Alipay.png" alt="宇宙小神特别萌 支付宝"><p>支付宝</p></div></div></div><footer class="post-footer"><div class="post-tags"><a href="/tags/Git/" rel="tag"><i class="fa fa-tag"></i> Git</a></div><div class="post-nav"><div class="post-nav-item"><a href="/posts/426039077.html" rel="prev" title="git-stash-用法"><i class="fa fa-chevron-left"></i> git-stash-用法</a></div><div class="post-nav-item"><a href="/posts/39002084.html" rel="next" title="git-同步远程仓库A和远程仓库B">git-同步远程仓库A和远程仓库B <i class="fa fa-chevron-right"></i></a></div></div></footer></article></div></div><div class="comments" id="valine-comments"></div><script>window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }</script></div><div class="toggle sidebar-toggle"><span class="toggle-line toggle-line-first"></span> <span class="toggle-line toggle-line-middle"></span> <span class="toggle-line toggle-line-last"></span></div><aside class="sidebar"><div class="sidebar-inner"><ul class="sidebar-nav motion-element"><li class="sidebar-nav-toc">文章目录</li><li class="sidebar-nav-overview">站点概览</li></ul><div class="post-toc-wrap sidebar-panel"><div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#一、两个仓库之间如何同步代码-，如何保持代码相同"><span class="nav-text">一、两个仓库之间如何同步代码 ，如何保持代码相同</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#方式一：在源A仓库或Fork的B仓库上执行同步"><span class="nav-text">方式一：在源A仓库或Fork的B仓库上执行同步</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1、将源项目代码同步到Fork出来的个人项目上："><span class="nav-text">1、将源项目代码同步到Fork出来的个人项目上：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2、将Fork出来的个人项目同步到源项目上："><span class="nav-text">2、将Fork出来的个人项目同步到源项目上：</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#方式二：分别git-push到A仓库和B仓库"><span class="nav-text">方式二：分别git push到A仓库和B仓库</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1、将A仓库代码同步到Fork出来的B仓库上："><span class="nav-text">1、将A仓库代码同步到Fork出来的B仓库上：</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#方式三：git-push-一次性推送到A和B仓库上-推荐"><span class="nav-text">方式三：git push 一次性推送到A和B仓库上(推荐)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#方式四：一次性推送到A和B仓库上-修改-git-config配置文件"><span class="nav-text">方式四：一次性推送到A和B仓库上(修改.git&#x2F;config配置文件)</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#二、仓库A和仓库B只同步部分文件"><span class="nav-text">二、仓库A和仓库B只同步部分文件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#三、git克隆或下载一个A仓库单个文件夹-，并push到B仓库里"><span class="nav-text">三、git克隆或下载一个A仓库单个文件夹 ，并push到B仓库里</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#四、仓库源A和Fork的仓库B-只同步部分文件"><span class="nav-text">四、仓库源A和Fork的仓库B 只同步部分文件</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#假如：A远程仓库的pro分支commit-10次-，B远程仓库pro分支commit-5次"><span class="nav-text">假如：A远程仓库的pro分支commit 10次 ，B远程仓库pro分支commit 5次</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#思路：创建本地仓库-，且与多个远程仓库关联-，再关联远程分支"><span class="nav-text">思路：创建本地仓库 ，且与多个远程仓库关联 ，再关联远程分支</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#例如：合并本地分支的某个文件或文件夹"><span class="nav-text">例如：合并本地分支的某个文件或文件夹</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#例如：合并某次的commit提交内容"><span class="nav-text">例如：合并某次的commit提交内容</span></a></li></ol></li></ol></div></div><div class="site-overview-wrap sidebar-panel"><div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person"><img class="site-author-image" itemprop="image" alt="宇宙小神特别萌" src="/my-images/avatar.gif"><p class="site-author-name" itemprop="name">宇宙小神特别萌</p><div class="site-description" itemprop="description">人生就是一次幸运的旅行！</div></div><div class="site-state-wrap motion-element"><nav class="site-state"><div class="site-state-item site-state-posts"><a href="/archives/"><span class="site-state-item-count">116</span> <span class="site-state-item-name">文章</span></a></div><div class="site-state-item site-state-tags"><a href="/tags/"><span class="site-state-item-count">27</span> <span class="site-state-item-name">标签</span></a></div></nav></div><div class="links-of-author motion-element"><span class="links-of-author-item"><a href="https://github.com/zhengjiaao" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;zhengjiaao" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a> </span><span class="links-of-author-item"><a href="https://www.jianshu.com/u/70d69269bd09" title="简书 → https:&#x2F;&#x2F;www.jianshu.com&#x2F;u&#x2F;70d69269bd09" rel="noopener" target="_blank"><i class="fa fa-fw fa-book"></i>简书</a> </span><span class="links-of-author-item"><a href="/atom.xml" title="RSS → &#x2F;atom.xml"><i class="fa fa-fw fa-rss"></i>RSS</a></span></div><div class="links-of-blogroll motion-element"><div class="links-of-blogroll-title"><i class="fa fa-fw fa-link"></i> 推荐阅读</div><ul class="links-of-blogroll-list"><li class="links-of-blogroll-item"><a href="https://github.com/spring-projects" title="https:&#x2F;&#x2F;github.com&#x2F;spring-projects" rel="noopener" target="_blank">spring-projects</a></li><li class="links-of-blogroll-item"><a href="http://www.alloyteam.com/nav/" title="http:&#x2F;&#x2F;www.alloyteam.com&#x2F;nav&#x2F;" rel="noopener" target="_blank">Web前端导航</a></li><li class="links-of-blogroll-item"><a href="http://www.chuangzaoshi.com/code" title="http:&#x2F;&#x2F;www.chuangzaoshi.com&#x2F;code" rel="noopener" target="_blank">创造狮导航</a></li></ul></div></div></div></aside><div id="sidebar-dimmer"></div></div></main><footer class="footer"><div class="footer-inner"><div class="copyright">&copy; <span itemprop="copyrightYear">2020</span> <span class="with-love"><i class="fa fa-heart"></i> </span><span class="author" itemprop="copyrightHolder">宇宙小神特别萌</span> <span class="post-meta-divider">|</span> <span class="post-meta-item-icon"><i class="fa fa-area-chart"></i> </span><span title="站点总字数">1.2m</span> <span class="post-meta-divider">|</span> <span class="post-meta-item-icon"><i class="fa fa-coffee"></i> </span><span title="站点阅读时长">17:41</span></div><div class="busuanzi-count"><script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><span class="post-meta-item" id="busuanzi_container_site_uv" style="display:none"><span class="post-meta-item-icon"><i class="fa fa-user"></i> </span><span class="site-uv" title="总访客量"><span id="busuanzi_value_site_uv"></span> </span></span><span class="post-meta-divider">|</span> <span class="post-meta-item" id="busuanzi_container_site_pv" style="display:none"><span class="post-meta-item-icon"><i class="fa fa-eye"></i> </span><span class="site-pv" title="总访问量"><span id="busuanzi_value_site_pv"></span></span></span></div></div></footer></div><script src="//cdn.jsdelivr.net/npm/animejs@3.1.0/lib/anime.min.js"></script><script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script><script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script><script src="//cdnjs.cloudflare.com/ajax/libs/velocity/1.2.1/velocity.min.js"></script><script src="//cdnjs.cloudflare.com/ajax/libs/velocity/1.2.1/velocity.ui.min.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/schemes/muse.js"></script><script src="/js/next-boot.js"></script><script src="/js/bookmark.js"></script><script>!function(){var t=document.createElement("script"),e=window.location.protocol.split(":")[0];t.src="https"===e?"https://zz.bdstatic.com/linksubmit/push.js":"http://push.zhanzhang.baidu.com/push.js";var s=document.getElementsByTagName("script")[0];s.parentNode.insertBefore(t,s)}()</script><script src="/js/local-search.js"></script><script>NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//cdnjs.cloudflare.com/ajax/libs/valine/1.3.10/Valine.min.js', () => {
    <!--var GUEST = ['nick', 'mail', 'link'];-->
    var GUEST = ['nick', 'mail'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el: '#valine-comments',
      verify: false,
      notify: false,
      appId: 'OuyHeA0XGL8hK4vgbqL0iERx-gzGzoHsz',
      appKey: 'L58VglKmWULcGK2W2AN7kWzM',
      placeholder: "留下邮箱，有回复时你将收到提醒，邮箱不会被公开。",
      avatar: 'wavatar',
      meta: guest,
      pageSize: '10' || 10,
      visitor: true,
      lang: 'zh-cn' || 'zh-cn',
      path: location.pathname,
      recordIP: true,
      serverURLs: ''
    });
  }, window.Valine);
});</script><script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({pluginRootPath:"live2dw/",pluginJsPath:"lib/",pluginModelPath:"assets/",tagMode:!1,model:{jsonPath:"/live2dw/assets/wanko.model.json"},display:{position:"right",width:150,height:300},mobile:{show:!1},log:!1})</script></body><script type="text/javascript" src="/js/src/activetitle.js"></script></html><!-- rebuild by neat -->